import * as actionTypes from '../../actions/ActionTypes';

import { handleActions } from 'redux-actions';


const defData = {
    userList:[]
}

export const selUserAllReducer = handleActions({
    [actionTypes.SEL_USER]: {
        next(state, action) {
            if(action.payload.page!=1){//不是第一页时追加userList
                action.payload.userList = state.data.userList.concat(action.payload.userList);
            }
            return { ret: true, isloading:false, data: action.payload };
        },
        throw(state, action) {
            return { ret: false, isloading:false, data: defData };
        }
    }
}, { ret: true, isloading:true, data: defData });

const defUser = {
    userInfo:{},
    isloading:true//是否读取ing1
}

export const selUserByIdReducer = handleActions({
    [actionTypes.SEL_USER_INFO]: {
        next(state, action) {
            return { ret: true, data: action.payload };
        },
        throw(state, action) {
            return { ret: false, statusText: "报错", data: defUser };
        }
    }
}, { ret: true, statusText: '默认', data: defUser });